<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        if(session('?username')){
            $title = M('settings')->where(array('name'=>'title'))->find();
            $this->assign('title', $title['value']);
            $this->assign('username', session('username'));

            $this->display('index');
        }else{
            $this->redirect('/User/Index/login');
        }
    }

    
    public function add_finger(){
        if(session('?username')){
            $this->display('add_finger');
        }else{
            $this->redirect('/User/Index/login');
        }
    }

    public function list_finger(){
        if(session('?username')){
            $this->display('list_finger');
        }else{
            $this->redirect('/User/Index/login');
        }
    }

    public function scan_log(){
        if(session('?username')){
            $this->display('scan_log');
        }else{
            $this->redirect('/User/Index/login');
        }
    }

    public function finger_detail(){
        if(session('?username')){
            $id = I('get.id');
            $finger = M('fingers')->where(array('id' => $id))->find();

            $this->assign('finger', $finger);
            $this->display('finger_detail');
        }else{
            $this->redirect('/User/Index/login');
        }
    }

    public function scan_detail(){
        if(session('?username')){
            $id = I('get.id');
            $result = M('results')->where(array('id' => $id))->find();
            $fingers = M('scan_logs')
                        ->join('fingers on scan_logs.finger_id = fingers.id','left')
                        ->field('scan_logs.id, fingers.app_name, fingers.app_version')
                        ->where(array('scan_logs.result_id'=>$id, 'scan_logs.result'=>1))->select();

            $this->assign('headers', unserialize($result['header']));
            $this->assign('fingers', $fingers);
            $this->display('scan_detail');
        }else{
            $this->redirect('/User/Index/login');
        }
    }
}